package cn.itcast.classSM.service.Impl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.classSM.dao.TeacherRepository;
import cn.itcast.classSM.domain.MainCheckMessage;
import cn.itcast.classSM.service.TeacherService;
@Service
@Transactional
public class TeacherServiceImpl implements TeacherService{

	@Autowired
	private TeacherRepository teacherRepository;
	
	@Override
	public void add(MainCheckMessage checkMessage) {
		// TODO Auto-generated method stub
		teacherRepository.save(checkMessage);
	}

	@Override
	public List<MainCheckMessage> findByMessage(Integer classMessage,String TimeMessage) {
		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
			Date date = format.parse(TimeMessage);
			if(classMessage != null){
				return teacherRepository.findByTimeAndClazz(classMessage,date);
			}else{
				return teacherRepository.findByTime(date);
			}
		} catch (ParseException e) {
			e.printStackTrace();
			return null;
		}
		
	}

}
